package com.superm.easy.cloud.commons.enums;

import com.superm.easy.cloud.commons.exception.IMessage;
import com.superm.easy.cloud.commons.util.MessageUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ResponseMsg implements IMessage {
    JSON_EXCEPTION_CODE("-10000"),
    PARSE_EXCEPTION_CODE("-10001"),
    AES_EXCEPTION_CODE("-10002"),

    EXCEPTION_CODE("-10003"),

    V2_VERSION_EXCEPTION_CODE("-10004"),

    ERR_INVALID_TOKEN_TYPE("20301"),
    ERR_INVALID_USER_ID("20302"),
    ERR_USER_LOCKED("20303"),
    ERR_USER_EXISTED("20304"),
    //	PARSE_EXCEPTION_CODE("20002"),

    V2_SUCCESS_CODE("20000"),
    V2_RESULT_EMPTY_CODE("20200"),
    V2_HMAC_REQUIRED_CODE("20201"),
    V2_HMAC_INVALID_CODE("20202"),

    V2_SEQ_REQUIRED_CODE("20203"),
    V2_SEQ_INVALID_CODE("20204"),

    V2_VERSION_REQUIRED_CODE("20205"),
    V2_MODEL_REQUIRED_CODE("20206"),

    V2_FILETYPE_REQUIRED_CODE("20207"),
    V2_FULLNAME_REQUIRED_CODE("20208"),
    V2_DURATION_REQUIRED_CODE("20209"),
    V2_STARTTIME_REQUIRED_CODE("20210"),
    V2_ENDTIME_REQUIRED_CODE("20211"),
    V2_ORDER_REQUIRED_CODE("20212"),
    V2_AUTHCODE_REQUIRED_CODE("20213"),
    V2_AUTHTYPE_REQUIRED_CODE("20214"),
    V2_AUTHTYPE_INVALID_CODE("20215"),

    V2_MAC_REQUIRED_CODE("20216"),
    V2_MAC_INVALID_CODE("20217"),

    V2_QRCODE_REQUIRED_CODE("20218"),
    V2_QRCODE_INVALID_CODE("20219"),
    V2_QRCODE_DUPAUTH_CODE("20220"),

    V2_TOKEN_REQUIRED_CODE("20230"),
    V2_TOKEN_INVALID_CODE("20231"),
    V2_TOKEN_RENEW_CODE("20232"),

    V2_UID_REQUIRED_CODE("20240"),
    V2_UID_INVALID_CODE("20241"),
    V2_UID_NOT_EXIST_CODE("20242"),
    V2_UID_BOUND_CODE("20243"),

    V2_ACCOUNT_REQUIRED_CODE("20250"),
    V2_ACCOUNT_FORMAT_INCORRECT_CODE("20251"),
    V2_ACCOUNT_INVALID_CODE("20252"),
    V2_ACCOUNT_NOT_EXIST_CODE("20253"),
    V2_ACCOUNT_IS_EXIST_CODE("20254"),

    V2_PASSWORD_REQUIRED_CODE("20260"),
    V2_PASSWORD_INVALID_CODE("20261"),
    V2_PASSWORD_LENGTH_INVALID_CODE("20262"),

    V2_TYPE_REQUIRED_CODE("20265"),
    V2_TYPE_INVALID_CODE("20266"),
    V2_NUMBER_REQUIRED_CODE("20267"),
    V2_NUMBER_INVALID_CODE("20268"),

    V2_TIME_REQUIRED_CODE("20270"),
    V2_MD5_REQUIRED_CODE("20271"),
    V2_TIMEOUT_CODE("20272"),
    V2_NONE_REQUIRED_CODE("20273"),
    V2_APP_REJECT_CODE("20274"),

    V2_AUTH_LOGIN_ERROR_CODE("20280"),

    V2_APP_VERSION_REQUIRED_CODE("20290"),

    V2_SYNC_FAILED_CODE("20300"),

    V3_INTER_VERSION_REQUIRED_CODE("30101"),
    V3_BINDPASS_REQUIRED_CODE("30102"),
    V3_BINDPASS_INVALID_CODE("30103"),
    V3_BIND_LIMIT_CODE("30104"),
    V3_BINDPASS_TIMEOUT_CODE("30105"),
    V3_INTERFACE_VERSION_INVALID_CODE("30201"),

    V3_PUSH_FLAG_REQUIRED_CODE("30301"),
    V3_PUSH_FLAG_INVALID_CODE("30302"),
    V3_UPLOAD_FLAG_REQUIRED_CODE("30303"),
    V3_UPLOAD_FLAG_INVALID_CODE("30304"),

    V3_REGISTER_FORBIDDEN_CODE("30301"),
    V3_ADD_FORBIDDEN_CODE("30302"),

    V4_PARAM_INVALID_CODE("40000"),
    V4_SUFFIX_REQUIRED_CODE("40101"),
    V4_TOO_MANY("40102"),
    V4_PINCODE_MISMATCH("40103"),
    V4_PINCODE_REQUIRED_CODE("40104"),

    V4_ACCOUNT_INACTIVATE_CODE("40110"),
    V4_ACCOUNT_VALIDATION_MISMATCH_CODE("40111"),
    V4_ACCOUNT_VALIDATION_EXPIRE_CODE("40112"),
    V4_ACCOUNT_SEND_MAIL_FAIL_CODE("40113"),
    V4_ACCOUNT_ACTIVATE_CODE("40114"),
    V4_VALIDATION_CODE_FAIL_CODE("40120"),
    V4_REQUEST_FAILED_CODE("40122"),

    V4_TNP_INVALID_ID("40201"),
    V4_TNP_INVALID_IP("40202"),

    V4_INTERNAL_ERROR_CODE("40222"),
    V4_PROCCESS_FAILED_CODE("40300"),

    V4_SERVICE_DISABLED("40401"),
    V4_SERVICE_EXPIRED("40402"),
    V4_TASK_TYPE_UNSUPPORT("40450"),
    V4_TASK_TASK_NOT_FOUND("40451"),
    V4_TASK_PROC_NOT_ALLOWED("40452"),

    V4_SHAREINVITATION_EXPIRED_CODE("41401"),
    V4_SHARENUMBER_EXCEEDED_CODE("41402"),
    V4_SHAREDEVICE_DUPLICATED_CODE("41403"),
    V4_SHAREINVITATION_SHARETOKEN_INVALID_CODE("41404"),
    V4_SHAREINVITATION_SHARETOKEN_REQUIRED_CODE("41405"),
    V4_SHAREDEVICE_SHARERECORD_NOTEIXIST_CODE("41406"),
    V4_SHAREDEVICE_GETPASSWORD_FAILURE_CODE("41407"),
    V4_SHAREDEVICE_LANGUAGE_INVALID_CODE("41408"),
    V4_SHAREDEVICE_CANNT_SHARETOYOUSELF_CODE("41409"),
    V4_SHAREINVITATION_INVALID_STATE("41410"),
    V4_SHAREINVITATION_INVALID_ID("41411"),
    V4_SHAREDEVICE_EXIST("41412"),
    V4_SHAREINVITATION_EXIST("41413"),
    V4_SHAREINVITATION_INVALID_SHARDTO_ID("41414"),

    V5_PUSH_INVALID_TIME_PERIOD("50101"),
    V5_DATA_REQUIRED_CODE("50102"),

    V5_DEVICE_PINCODE_MISMATCH_CODE("51125"),

    V5_INVALID_PRODUCTID_FAILURE_CODE("51004"),
    V5_PRODUCTCHANNEL_REQUIRED_CODE("51005"),
    V5_PRODUCTCHANNEL_INVALID_CODE("51006"),
    V5_PRODUCTCURRENCY_REQUIRED_CODE("51007"),
    V5_ORDERCODE_REQUIRED_CODE("51008"),
    V5_PAYRESULT_REQUIRED_CODE("51009"),
    V5_UNPAIDORDER_EXISTS_CODE("51010"),
    V5_ORDER_NOTEXISTS_CODE("51011"),
    V5_CANCEL_ORDER_FAILURE_CODE("51012"),
    V5_ONLYUNPAIDCORDER_CANBECANCELLED_CODE("51013"),
    V5_PRODUCTNAME_REQUIRED_CODE("51014"),
    V5_PRODUCTDESCRIPTION_REQUIRED_CODE("51015"),
    V5_DEVICE_NOCSCHARGECARD_CODE("51016"),
    V5_ORDERCODE_DUPLICATED_CODE("51017"),
    V5_CSCHARGE_PASSWORD_INVALID_CODE("51018"),
    V5_CSCHARGE_SKU_INVALID_CODE("51019"),
    V5_PAYMENTTYPE_REQURIED_CODE("51020"),
    V5_PAYMENTTYPE_REQUIRED_CODE("51021"),
    V5_UID_NOTALLOWED_SUBMITORDER_CODE("51022"),
    V5_PRODUCTATTRIBUTE_INVALID_CODE("51023"),
    V5_PRODUCTID_INVALID_CODE("51024"),

    V5_PREMIUM_ABILITY_EXPIRED("51051"),

    V5_REQUEST_FAILED_CODE("51122"),
    V5_QUERY_NOORDER_CODE("51123"),
    V5_BRAINTBREE_SUBSCRIPTIONACTIVE_CODE("51124"),
    V5_BRAINTBREE_INVALIDPAYMENTMETHOD_CODE("51125"),
    V5_BRAINTBREE_CANCELSUBSCRIPTION_FAILURE_CODE("51126"),
    V5_BRAINTBREE_GENERATESUBSCRIPTION_FAILURE_CODE("51127"),
    V5_BRAINTBREE_NOCUSTOMERDRELEATED_FAILURE_CODE("51128"),
    V5_BRAINTBREE_SUBSCRIPTIONPOSTDUE_FAILURE_CODE("51129"),
    V5_BRAINTBREE_ACTIVESUBSCRIPTIONALREADY_FAILURE_CODE("51130"),
    V5_BRAINTBREE_SUBSCRIPTIONINTRIAL_FAILURE_CODE("51131"),
    V5_BRAINTBREE_SUBSCRIPTIONID_REQUIRED_CODE("51135"),
    V5_PAYPAL_SUBSCRIPTIONID_REQUIRED_CODE("51132"),
    V5_PAYPAL_SUBSCRIPTIONID_INVALID_CODE("51133"),
    V5_SUBSCRIPTIONID_NOTRIAL_CODE("51134"),
    V5_SUBSCRIPTION_EXIST_CODE("51135"),
    V5_COUPON_EXCEED_LIMITEDNUM_CODE("51136"),
    V5_INVALID_COUPONCODE_CODE("51137"),
    V5_COUPONCODE_REQUIRED_CODE("51138"),
    V5_23HOURS_FREETIRAL_EQUIP_MODEL_NOTSUPPORTED_CODE("51139"),
    V5_23HOURS_FREETIRAL_STATUS_INVALID_CODE("51140"),
    V5_PAYPAL_ORDERID_ISNULL("51148"),
    V5_23HOURS_FREETIRAL_STATUS_REQUIRED_CODE("51145"),

    V5_APPLEPAY_IAP_RECEIPT_REQUIRED_CODE("51139"),
    V5_APPLEPAY_IAP_PAYMENT_FAILURE_CODE("51140"),
    V5_APPLEPAY_IAP_RENEW_ORTHERUSER_CODE("51141"),
    V5_APPLEPAY_IAP_IDENTIFIER_PRODUCTID_NOMATCH_CODE("51142"),
    V5_DID_NOT_EXIST("54003"),
    V5_CLOUD_SCENE_TYPE_NOT_SUPPORT("53006"),
    V5_APPLEPAY_IAP_ORDER_PAID_ALREADY("51143"),
    V5_APPLEPAY_IAP_ORDER_EXIST_ALREADY_CODE("51146"),

    V5_AESNUM_NOT_EXIST("54002"),
    V5_MUILTIPLE_EQUIPMENT_OWNER("54004"),
    V5_RELATION_NOT_EXIST("54005"),
    V5_RELATION_NOT_MATCHED("54006"),
    V5_EQUIPMENT_NOT_OWNED_BY_USER("54007"),
    V5_START_PAGESIZE_ISNULL("54008"),
    V5_ROUND_ISNULL("54009"),
    V5_PROXIED_DEVICE_INVALID("54010"),
    V5_DEVICE_NOT_NEW("54011"),
    V5_DEVICE_IS_NEW("54012"),
    V5_NOONLIGHT_ERROR("54013");

    private String code;

    @Override
    public String getMessage(Object... params) {
        return (null != params && params.length > 0) ? MessageUtil.getErrMsg(code) : MessageUtil.getErrMsg(code, params);
    }

    public static ResponseMsg of(String code) {
        for (ResponseMsg msg : ResponseMsg.values()) {
            if (msg.getCode().equals(code)) {
                return msg;
            }
        }
        return ResponseMsg.EXCEPTION_CODE;
    }
}
